package hot100.logos21To30;

import hot100.datastruct.ListNode;

/**
 * @author logos
 * date 2025/7/12 13:24
 * @version v1.0
 * @Package hot100
 */
public class logos25 {

    /**
     * 25.环形链表
     * https://leetcode.cn/problems/linked-list-cycle/?envType=study-plan-v2&envId=top-100-liked
     */

    public boolean hasCycle(ListNode head) {
        if (head == null || head.next == null) {
            return false;
        }
        ListNode fast = head.next.next;
        ListNode slow = head.next;
        while (fast != slow) {
            if (fast == null || fast.next == null) {
                return false;
            }
            fast = fast.next.next;
            slow = slow.next;
        }
        return true;
    }
}
